/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.bridge.major;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import ru.jSkyRoom.interfaces.major.Ammo;
import ru.jSkyRoom.interfaces.major.Keyword;
import ru.jSkyRoom.interfaces.major.Projectile;
import ru.jSkyRoom.interfaces.stub.JSkySound;
import ru.jSkyRoom.interfaces.sub.JSkyModel;
import skyproc.AMMO;
import skyproc.FormID;
import skyproc.Model;

/**
 *
 * @author Rakev
 */
public class AmmoBridge extends DescriptionedMajorBridge<AMMO> implements Ammo {

    public AmmoBridge(AMMO adapting) {
        super(adapting);
    }

    @Override
    public Set<Keyword> getKeywords() {
        Collection<FormID> keyWordFormIds = getRawObject().getKeywordSet().getKeywordRefs();
        Collection<Keyword> keyWords = getFinderFactory().createKeywordFinder().find(keyWordFormIds);

        return Collections.unmodifiableSet(new HashSet<>(keyWords));
    }

    @Override
    public void addKeyword(Keyword keyword) {
        getRawObject().getKeywordSet().addKeywordRef(keyword.getForm());
    }

    @Override
    public void removeKeyword(Keyword keyword) {
        getRawObject().getKeywordSet().removeKeywordRef(keyword.getForm());
    }

    @Override
    public JSkyModel getModel() {
        Model model = getRawObject().getModelData();
        return getBridgeFactory().createBridge(model);
    }

    @Override
    public JSkySound getPickupSound() {
        FormID soundId = getRawObject().getPickupSound();
        return getFinderFactory().createJSkySoundFinder().find(soundId);
    }

    @Override
    public void setPickupSound(JSkySound sound) {
        FormID id = getIdProducer().produce(sound);
        getRawObject().setPickupSound(id);
    }

    @Override
    public JSkySound getDropSound() {
        FormID soundId = getRawObject().getDropSound();
        return getFinderFactory().createJSkySoundFinder().find(soundId);
    }

    @Override
    public void setDropSound(JSkySound sound) {
        FormID id = getIdProducer().produce(sound);
        getRawObject().setDropSound(id);
    }

    @Override
    public Projectile getProjectile() {
        FormID id = getRawObject().getProjectile();
        return getFinderFactory().createProjectileFinder().find(id);
    }

    @Override
    public void setProjectile(Projectile projectile) {
        FormID id = getIdProducer().produce(projectile);
        getRawObject().setProjectile(id);
    }

    @Override
    public boolean getFlag(AMMO.AMMOFlag flag) {
        return getRawObject().get(flag);
    }

    @Override
    public void setFlag(AMMO.AMMOFlag flag) {
        getRawObject().set(flag, true);
    }

    @Override
    public void unsetFlag(AMMO.AMMOFlag flag) {
        getRawObject().set(flag, false);
    }

    @Override
    public int getValue() {
        return getRawObject().getValue();
    }

    @Override
    public void setValue(int value) {
        getRawObject().setValue(value);
    }

    @Override
    public float getDamage() {
        return getRawObject().getDamage();
    }

    @Override
    public void setDamage(float damage) {
        getRawObject().setDamage((float) damage);
    }
}
